package com.xyq;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class MapDemo {
    public static void main(String[] args) {
        test3();
    }

   public static void test0() {
       Map<String,Double> map= new HashMap<>();
       map.put("阿伟", 99.0);
       map.put("阿罡", 88.0);
       map.put("王五", 77.0);
       map.put("赵六", 66.0);
       map.put("赵六", 66.0);

        map.remove("王五");
        System.out.println(map);
        //map.clear();
        ///System.out.println(map);

        boolean b1=map.containsKey("赵六");
        System.out.println("b1 =" + b1);
        boolean b2=map.containsValue(66.0);
        System.out.println("b2 =" + b2);

        boolean empty=map.isEmpty();
        System.out.println("empty =" + empty);
        int size=map.size();
        System.out.println("size =" + size);
    }




    public static void test1() {
        Map<String,Double> map= new HashMap<>();
        map.put("阿伟", 99.0);
        map.put("阿罡", 88.0);
        map.put("王五", 77.0);
        map.put("赵六", 66.0);
        map.put("赵六", 66.0);

        Set<String> keySet=map.keySet();
        for (String key : keySet) {
            //根据key查找
            Double  value=map.get(key);
            System.out.println(key + "---" + value);
        }
    }
    public static void test2() {
        Map<String,Double> map= new HashMap<>();
        map.put("阿伟", 99.0);
        map.put("阿罡", 88.0);
        map.put("王五", 77.0);
        map.put("赵六", 66.0);
        map.put("赵六", 66.0);

        Set<Map.Entry<String, Double>> entrySet=map.entrySet();
        for (Map.Entry<String, Double> entry : entrySet){
            String key=entry.getKey();
            Double value=entry.getValue();
            System.out.println(key + "---" + value);
        }
    }
    public static void test3() {
        Map<String,Double> map= new HashMap<>();
        map.put("阿伟", 99.0);
        map.put("阿罡", 88.0);
        map.put("王五", 77.0);
        map.put("赵六", 66.0);
        map.put("赵六", 66.0);

        map.forEach(new BiConsumer<String, Double>() {
            @Override
            public void accept(String key, Double value) {
                System.out.println(key + "---" + value);

            }
        });
        map.forEach((key, value) -> System.out.println(key + "---" + value));

    }

}
